<template>
  <div class="homeWrap">
    <el-container style="height: 100vh">
      <!-- 侧边栏区域 -->
      <el-aside width="220px" style="height: 100vh">
        <div class="logo">
          <div class="img"><img src="@/assets/img/logo.png" /></div>
          纺织云平台
        </div>
        <!-- 侧边栏菜单区域 -->
        <el-scrollbar style="height: calc(100% - 60px)">
          <el-menu
            router
            :default-active="activePath"
            class="el-menu-vertical-demo"
            background-color="#fff"
            text-color="#292B3D"
            active-text-color="#2c67f6"
          >
            <template v-for="(item, index) in navList">
              <el-submenu
                v-if="item.children"
                :key="index"
                :index="String(index + 1)"
              >
                <template slot="title">
                  <span class="svg-container">
                    <svg-icon
                      :icon-class="item.icon"
                      class-name="custom-class"
                    />
                  </span>
                  <span>{{ item.title }}</span>
                </template>
                <el-menu-item
                  v-for="child in item.children"
                  :index="child.path"
                  :key="child.path"
                  @click="goPage(child.path)"
                  style="padding-left:50px"
                >
                  {{ child.title }}</el-menu-item
                >
              </el-submenu>
              <el-menu-item
                v-else
                :key="index"
                @click="goPage(item.path)"
                :index="item.path"
              >
                <span class="svg-container">
                  <svg-icon :icon-class="item.icon" class-name="custom-class" />
                </span>
                <span slot="title">{{ item.title }}</span>
              </el-menu-item>
            </template>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-container>
        <!-- 头部区域 -->
        <el-header>
          <div class="user-info">
            <el-button type="text" class="logout" @click="logout">
              <svg-icon icon-class="exit" class-name="custom-class" />
              退出</el-button
            >
          </div>
        </el-header>
        <!-- 右侧主体区域 -->
        <el-main>
          <div class="main-wrapper">
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { Logout } from '@/api/api.js';
import { removeToken } from '@/utils/auth';
export default {
  data() {
    const navList = [
      {
        title: '监控中心',
        icon: 'jiankong',
        children: [
          { title: '车间总览', path: 'WorkChart' },
          { title: '车台数据', path: 'WorkData' },
          { title: '实时开台', path: 'WorkActual' },
          { title: '生产看板', path: 'WorkProduct' }
        ]
      },
      {
        title: '生产统计',
        icon: 'tongji',
        children: [
          { title: '历史数据查询', path: 'ProductionData' },
          { title: '历史轨迹曲线', path: 'ProductionTrack' },
          { title: '参数修改记录', path: 'ProductionParams' },
          { title: '用工历史记录', path: 'ProductionWorker' }
        ]
      },
      {
        title: '告警管理',
        icon: 'baojing',
        children: [
          { title: '告警设置', path: 'Systemtion' },
          // { title: '告警明细', path: 'Systemrole' },
          { title: '告警监控', path: 'Basicperson' },
          { title: '告警统计', path: 'Basicment' }
        ]
      },
      {
        title: '能源管理',
        icon: 'baojing',
        children: [
          { title: '实时查询', path: 'EnergyActual' },
          { title: '历史数据', path: 'EnergyHistory' },
          { title: '电流折线图', path: 'EnergyLine' },
          { title: '品种电耗', path: 'EnergyPz' },
          { title: '工序电耗', path: 'EnergyGx' },
          { title: '电耗明细', path: 'EnergyDetail' }
        ]
      },
      {
        title: '环境管理',
        icon: 'huanjing',
        children: [
          { title: '实时查询', path: 'Environment' },
          { title: '历史数据', path: 'HistoryEnvironment' }
        ]
      },
      {
        title: '生产订单管理',
        icon: 'order',
        children: [
          { title: '订单管理', path: 'Basiclier' },
          { title: '订单跟踪', path: 'Salesreturn' }
        ]
      },
      {
        title: '生产计划管理',
        icon: 'jihua',
        children: [
          { title: '预排计划管理', path: 'PrePlan' },
          { title: '日计划管理', path: 'DailyPlan' },
          { title: '工艺单管理', path: 'ProcessPlan' },
          { title: '工艺单变更管理', path: 'ChangePlan' }
        ]
      },
      {
        title: '生产调度管理',
        icon: 'jihua',
        children: [
          { title: '人员管理', path: 'DispatchPersonnel' },
          { title: '排班管理', path: 'DispatchScheduling' },
          { title: '轮班管理', path: 'DispatchShifts' }
        ]
      },
      {
        title: '工单执行反馈',
        icon: 'gongdan',
        path: 'Socialsignin'
      },
      {
        title: '报表管理',
        icon: 'baojia',
        path: 'TableMan'
      },
      {
        title: '系统管理',
        icon: 'gongdan',
        children: [
          { title: '数据字典', path: 'Dict' },
          { title: '定额表管理', path: 'Quota' }
        ]
      },
      {
        title: '工资管理',
        icon: 'gongzi',
        children: [
          { title: '品种单价设定', path: 'Purchase' },
          { title: '品种单价设定添加', path: 'Purware' },
          { title: '计件工资算法管理', path: 'Purorder' },
          { title: '计件工资算法添加前纺清联', path: 'shopAdd' },
          { title: '计件工资日度核算管理', path: 'Loans' },
          { title: '计件工资月度核算管理', path: 'Payment' },
          { title: '计件工资数据修正', path: 'Authredirect' }
        ]
      },
      {
        title: '薪资报表',
        icon: 'gongzi',
        children: [
          // { title: '前纺', path: 'SalaryReportQianFang' },
          { title: '细纱', path: 'SalaryReportXiSha' }
          // { title: '络筒', path: 'SalaryReportLuoTong' }
        ]
      }
    ];
    return {
      navList,
      activePath: ''
    };
  },
  created: function() {
    let path = this.$route.path.split('/');
    this.activePath = path[1];
  },
  watch: {
    $route: function(to) {
      let path = this.$route.path.split('/');
      this.activePath = path[1];
    }
  },
  methods: {
    goPage(path) {
      this.$router.push({ path: `/${path}` });
    },
    logout() {
      this.$confirm('确定退出登录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Logout()
          .then(res => {
            if (res.code === 1) {
              removeToken();
              this.$router.push('/Login');
            } else {
              this.$notify.error({
                title: '错误',
                message: res.msg
              });
            }
          })
          .catch(error => {});
      });
    }
  }
};
</script>

<style lang="stylus" scoped>
.boxPassword {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.iframeStyle {
  width: 100%;
  height: 100%;
}

.el-dropdown-link {
  cursor: pointer;
  color: #FFFFFF;
}

.el-icon-arrow-down {
  font-size: 12px;
}

body {
  margin: 0;
}

.mid {
  margin-left: 30%;
}

.homeWrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.headerbutton {
  position: absolute;
  left: 15%;
}

// .headerbutton el-menu-item{
// padding:0px 15px
// }
.home-container {
  height: 100%;
}

.el-header {
  color: #fff;
  padding-left: 0 30px;
  font-size: 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background-color: #3E4A70;
  position: relative;

  >div {
    display: flex;
    align-content: center;
  }

  .user-info {
  }

  .logout {
    // color: #48556A;
    color:#fff;
  }
}

.admin {
  font-size: 13px;
}

.el-aside {
  background-color: #fff;
  box-shadow: 2px 0px 6px 0px rgba(206, 219, 225, 0.3);
  overflow: hidden;

  .logo {
    height: 60px;
    font-weight: 600;
    font-size: 18px;
    padding-left: 20px;
    line-height: 60px;
    background:#3E4A70;
    color:#fff;
    display: flex;
    align-items: center;

    .img {
      width: 40px;
      height: 36px;
      margin-right: 10px;
      background: #fff;
      border-radius:5px;
      display:flex;
      justify-content: center;
      align-items: center;
      img{
        width:35px;
        height:32px;
      }
    }
  }

  .el-menu {
    border-right: none
    padding 0 4px 0 0
    ::v-deep .el-submenu__title{
      height 50px
      line-height 50px
      border-left 3px solid transparent
    }

    ::v-deep .el-submenu__title:hover, ::v-deep .el-submenu.is-active .el-submenu__title {
      background-color: #F1F4FE !important;
      color: #2c67f6 !important;
      border-left 3px solid #2c67f6
      i {
        color: #2c67f6 !important;
      }
    }

    ::v-deep .el-menu-item:hover {
      background-color: #fff !important;
      color: #2c67f6 !important;

      i {
        color: #2c67f6 !important;
      }
    }

    ::v-deep .el-menu-item-group__title {
      padding: 0;
    }
  }
}

.svg-container {
  vertical-align: middle;
  width: 15px;
  margin-right: 10px;
  display: inline-block;
}

.el-main {
  background-color: #F6F9FC;
  width: 100%;
  height: calc(100% - 60px);
  padding: 14px;

  .main-wrapper {
    height: 100%;
    background: #fff;
    overflow-y: auto;
  }
}

.el-submenu .el-menu-item {
  // background-color: #f5f5f5;
  padding:0 45px 0 60px
}

.el-menu-item {
  height: 50px;
  line-height: 50px;
}

.el-menu-item-group div {
  padding: 0 !important;
}

.el-menu-vertical-demo {
  overflow: hidden;
}

.el-submenu__title {
  padding: 0 !important;
}
</style>
<style lang="scss">
// 页面通用样式
@import '../assets/css/style.scss';
</style>
